package com.tomhuang.service;

import com.tomhuang.dao.EmployeeMapper;
import com.tomhuang.pojo.Employee;
import com.tomhuang.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

public class EmpManagerDaoImpl implements EmployeeMapper {

    @Override
    public Employee findEmpById(int id) {
        return null;
    }

    @Override
    public Employee queryEmp(int id) {
        SqlSession sqlSession= MyBatisUtils.getSession();
        String sql="com.tomhuang.dao.EmployeeMapper.queryEmp";
        Employee employee=sqlSession.selectOne(sql,id);
        sqlSession.commit();
        sqlSession.close();
        return employee;

    }

    @Override
    public Boolean addEmp(Employee employee) {
        SqlSession sqlSession= MyBatisUtils.getSession();
        String sql="com.tomhuang.dao.EmployeeMapper.addEmp";
        int updateCount=sqlSession.update(sql,employee);
        sqlSession.commit();
        sqlSession.close();
        if(updateCount>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean delEmp(int id) {
        SqlSession sqlSession= MyBatisUtils.getSession();
        String sql="com.tomhuang.dao.EmployeeMapper.delEmp";
        int delete=sqlSession.update(sql,id);
        sqlSession.commit();
        sqlSession.close();
        if(delete>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Boolean updateEmp(Employee employee) {
        SqlSession sqlSession= MyBatisUtils.getSession();
        String sql="com.tomhuang.dao.EmployeeMapper.updateEmp";
        int updateCount=sqlSession.update(sql,employee);
        sqlSession.commit();
        sqlSession.close();
        if(updateCount>0){
            return true;
        }else{
            return false;
        }
    }
}
